'use strict';
const dayjs = require("dayjs");
const {getDefaultModelConfig} = require("../../utils/common");

module.exports = app => {
    const { STRING, INTEGER, DATE, TINYINT, BIGINT, TEXT } = app.Sequelize;
    const PostComment = app.model.define(
        'PostComment',
        {
            id: {type: BIGINT, primaryKey: true, autoIncrement: true},
            post_id: {type: BIGINT, allowNull: false},
            user_id: {type: BIGINT, allowNull: false},
            parent_id: {type: BIGINT, defaultValue: null},
            reply_to_user_id: {type: BIGINT, defaultValue: null},
            content: {type: TEXT, allowNull: false},
            status: {
                type: TINYINT,
                defaultValue: 1,
                // 1-正常，0-已删除，2-已屏蔽
            },
            creator: {type: BIGINT, defaultValue: 0},
            updater: {type: BIGINT, defaultValue: 0},
            deleted: {type: TINYINT, defaultValue: 0},
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'post_comment',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );


    PostComment.associate = function () {
        app.model.Business.PostComment.belongsTo(app.model.Business.User, {
            foreignKey: 'user_id',
            targetKey: 'id',
            as: 'user'
        });
        app.model.Business.PostComment.belongsTo(app.model.Business.User, {
            foreignKey: 'reply_to_user_id',
            targetKey: 'id',
            as: 'replyUser'
        });
        app.model.Business.PostComment.belongsTo(app.model.Business.Post, {
            foreignKey: 'post_id',
            targetKey: 'id',
            as: 'post'
        });
    };
    return PostComment
};
